#!/bin/bash

# 修复剩余的分页问题

echo "修复剩余的分页问题..."

# 需要修复的文件列表
files=(
    "fuint-application/src/main/java/com/fuint/common/service/impl/OpenGiftServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/UserCouponServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/RefundServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/SettlementServiceImpl.java"
    "fuint-application/src/main/java/com/fuint/common/service/impl/OrderServiceImpl.java"
)

for file in "${files[@]}"; do
    if [ -f "$file" ]; then
        echo "正在修复文件: $file"
        
        # 1. 修复错误的 page.getRecords() 和 page.getTotal() 使用
        sed -i 's/page\.getRecords()/pageResult.getRecords()/g' "$file"
        sed -i 's/page\.getTotal()/pageResult.getTotal()/g' "$file"
        sed -i 's/page\.getCurrent()/pageResult.getCurrent()/g' "$file"
        sed -i 's/page\.getSize()/pageResult.getSize()/g' "$file"
        sed -i 's/page\.getPages()/pageResult.getPages()/g' "$file"
        
        # 2. 修复 convertToPaginationResponse 调用中的参数
        sed -i 's/pageNumber, pageSize, page\.getTotal()/(int)pageResult.getCurrent(), (int)pageResult.getSize(), pageResult.getTotal()/g' "$file"
        sed -i 's/paginationRequest\.getCurrentPage(), paginationRequest\.getPageSize(), page\.getTotal()/(int)pageResult.getCurrent(), (int)pageResult.getSize(), pageResult.getTotal()/g' "$file"
        
        # 3. 修复一些特殊情况
        sed -i 's/List<.*> dataList = mtUserCouponMapper\.selectList(lambdaQueryWrapper);/Page<MtUserCoupon> pageResult = mtUserCouponMapper.selectPage(page, lambdaQueryWrapper);\n        List<MtUserCoupon> dataList = pageResult.getRecords();/g' "$file"
        sed -i 's/List<.*> orderList = mtOrderMapper\.selectList(lambdaQueryWrapper);/Page<MtOrder> pageResult = mtOrderMapper.selectPage(page, lambdaQueryWrapper);\n        List<MtOrder> orderList = pageResult.getRecords();/g' "$file"
        
        echo "已修复文件: $file"
    else
        echo "文件不存在: $file"
    fi
done

echo "剩余分页问题修复完成！"
